import gdata.docs.data
import gdata.docs.client
import gdata.spreadsheet.service
import sys

c = gdata.spreadsheet.service.SpreadsheetsService()
client = gdata.docs.client.DocsClient()
client.ssl = True
c.email = 'science.uoit@gmail.com'
c.password = sys.argv[1]
c.ProgrammaticLogin()
client.ClientLogin(email='science.uoit@gmail.com',
                   password=sys.argv[1],
                   source="uoit-pages")

## Create a folder

(account, version) = sys.argv[2:4]
foldername = "pages - %s - %s" % (account, version)

# find the Science Pages folder
root = None
for f in client.GetDocList(uri="/feeds/default/private/full/-/folder").entry:
  if f.title.text == 'Science Pages':
    root = f
  if f.title.text == foldername:
    print "Target folder already exists"
    sys.exit(0)

new_folder = client.Create(gdata.docs.data.FOLDER_LABEL, 
                           "pages - %s - %s" % (account, version),
                           root)

print "Done"
